package com.milloc.db.controller;

import com.milloc.db.dto.TestDTO;
import com.milloc.db.service.SQLRunnerService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author gongdeming
 * @create 2019-09-04
 */
@RestController
@RequestMapping("/test")
public class TestController {
    private final SQLRunnerService sqlRunnerService;

    public TestController(SQLRunnerService sqlRunnerService) {
        this.sqlRunnerService = sqlRunnerService;
    }

    @PostMapping("/sql")
    public Object testSQL(@RequestBody TestDTO testDTO) {
        sqlRunnerService.reloadSQL(testDTO.getSqlEntity().getId());
        return sqlRunnerService.runSQL(testDTO.getSqlEntity(), testDTO.getParams());
    }
}
